### disaster_ai_demo/app.py

import streamlit as st
import base64
from model.predictor import classify_image
from generator.text_gen import generate_suggestion

st.set_page_config(page_title="灾情识别AI助手", layout="centered")
st.title("🚨 卫星图像灾情识别 Demo")

uploaded = st.file_uploader("请上传卫星图像", type=['jpg', 'jpeg', 'png'])

if uploaded:
    st.image(uploaded, caption="上传图像", use_column_width=True)
    with st.spinner("正在识别中..."):
        image_bytes = uploaded.read()
        base64_img = base64.b64encode(image_bytes).decode("utf-8")

        result = classify_image(base64_img)

        st.subheader("🧾 识别结果")
        st.write("类型：", result["label"])
        st.write(f"置信度：{result['score']:.2f}")

        st.subheader("🟥 风险等级")
        st.write(result["level"])

        st.subheader("📢 应急建议")
        suggestion = generate_suggestion(result['label'], result['level'])
        st.success(suggestion)